using System;
using System.Runtime.InteropServices;


public class DeviceListener  
{
	[DllImport("User32.dll")]
	private static extern bool GetLastInputInfo(ref LastInputInfo plii);

	public static DateTime LastActivity()
	{
			var lastInputInfo = new LastInputInfo();
			lastInputInfo.cbSize = (uint) Marshal.SizeOf(lastInputInfo);

			GetLastInputInfo(ref lastInputInfo);

			return DateTime.Now.AddMilliseconds(-(Environment.TickCount - lastInputInfo.dwTime));
	}

	[StructLayout(LayoutKind.Sequential)]
	private struct LastInputInfo
	{
		public uint cbSize;
		public readonly uint dwTime;
	}
}
